package com.mytaobao.requestlayer;

import com.baseproject.datasource.Repository;
import com.baseproject.datasource.get.procedure.DataProcedure;
import com.baseproject.datasource.get.request.type.JsonArrayRequestType;
import com.baseproject.datasource.get.request.type.ListRequestType;
import com.mytaobao.main.cart.func.cart.ItemCommodity;
import com.mytaobao.main.firsttab.func.guessyoulike.ItemGuessYouLike;

import org.json.JSONArray;

import java.util.List;

import rx.Observable;

import static com.baseproject.appconfig.ConstUrlBaseProject.TEST_URL;
import static com.mytaobao.AppConfig.ConstUrl.TEST_CART_URL;
import static com.mytaobao.util.Const.KET_SAVE_PATH_FIRST_TAB;
import static com.mytaobao.util.Const.KET_SAVE_PATH_GUESSYOULIKE;
import static com.mytaobao.util.Const.KET_SAVE_PATH_MY_CART;

/**
 * Created by hp on 2017/9/1.
 */

public class AppRequest {

    public static Observable<List<ItemCommodity>> getCommodity() {
        return getCommodity(DataProcedure.createCommon(ItemCommodity.class));
    }

    public static Observable<List<ItemCommodity>> getCommodity(DataProcedure dataProcedure) {
        return Repository.getInstance().getList(dataProcedure.setRequestParams(KET_SAVE_PATH_MY_CART, TEST_CART_URL)
                        .setRequestType(new ListRequestType()), dataProcedure.getClassName());
    }


    public static Observable<List<JSONArray>> getFirstTab() {
        return getFirstTab(DataProcedure.createCommon(JSONArray.class));
    }

    public static Observable<List<JSONArray>> getFirstTab(DataProcedure dataProcedure) {
        return Repository.getInstance().getList(dataProcedure.setRequestParams(KET_SAVE_PATH_FIRST_TAB, TEST_URL)
                .setRequestType(new JsonArrayRequestType()), dataProcedure.getClassName());
    }


    public static Observable<List<ItemGuessYouLike>> getGuessYouLikeList() {
        return getGuessYouLikeList(DataProcedure.createCommon(ItemGuessYouLike.class));
    }

    public static Observable<List<ItemGuessYouLike>> getGuessYouLikeList(DataProcedure dataProcedure) {
        return Repository.getInstance().getList(dataProcedure.setRequestParams(KET_SAVE_PATH_GUESSYOULIKE, TEST_URL)
                .setRequestType(new JsonArrayRequestType()), dataProcedure.getClassName());
    }

}
